#include <cstdio>
#include <cstring>

int n, m, f[ 210 ][ 210 ];

void init( )
{
    int i, u, v;
    memset( f, 0, sizeof( f ) );
    for ( i = 0; i < m; i++ )
    {
        scanf("%d%d", &u, &v); u--; v--;
        f[ u ][ v ] = 1;
    }
}

void work( )
{
    int ans = n * ( n - 1 ) / 2, i, j, k;
    for ( k = 0; k < n; k++ )
        for ( i = 0; i < n; i++ )
            for ( j = 0; j < n; j++ )
                if ( f[ i ][ k ] && f[ k ][ j ] )
                    if ( f[ i ][ j ] < f[ i ][ k ] + f[ k ][ j ] )
                        f[ i ][ j ] = f[ i ][ k ] + f[ k ][ j ];
    for ( i = 0; i < n; i++ )
        for ( j = 0; j < n; j++ )
            if ( f[ i ][ j ] > 1 )
                ans--;
    printf("%d\n", ans);
}

int main( )
{
    while ( scanf("%d%d", &n, &m) != EOF )
    {
        init( );
        work( );
    }
    return 0;
}
